<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- 使用JSTL标签需要引入的头文件 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!-- 使用fmt 对时间进行格式化的时候需要引入的头文件 -->
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function checkForm(){
		var title=document.getElementById("title").value;
		/* 用ckeditor取其内容 */
		var content=CKEDITOR.instances.content.getData();
		var typeId=document.getElementById("typeId").value;
		if(title==null||title==""){
			document.getElementById("error").innerHTML="标题不能为空！";
			return false;
		}
		if(content==null||content==""){
			document.getElementById("error").innerHTML="内容不能为空！";
			return false;
		}
		if(typeId==null||typeId==""){
			document.getElementById("error").innerHTML="请选择日志类别！";
			return false;
		}
		return true;
	}
</script>
</head>
<body>
<div class="data_list">
		<div class="data_list_title">
			<c:choose>
				<c:when test="${diary.diaryId!=null }">
					<img src="${pageContext.request.contextPath}/images/diary_type_edit_icon.png"/>
					修改日记
				</c:when>
				<c:otherwise>
					<img src="${pageContext.request.contextPath}/images/diary_add_icon.png"/>
					写日记
				</c:otherwise>
			</c:choose>
		</div>
		<!-- 写日志表单部分 -->
		<form action="diary?action=save" method="post" onsubmit="return checkForm()">
			<div>
				<!-- 日志标题部分 -->
				<div class="diary_title"><input type="text" id="title"  name="title" value="${diary.title }" class="input-xlarge"  style="margin-top:5px;height:30px;"  placeholder="日志标题..."/></div>
				<!-- ckeditor在线文本编辑器 -->
				<div>
					<textarea class="ckeditor" id="content" name="content">${diary.content }</textarea>
				</div>
				<!-- 选择日志类别部分 -->
				<div class="diary_type">
					<select id="typeId" name="typeId">
						<option value="">请选择日志类别...</option>
						<c:forEach var="diaryTypeCount" items="${diaryTypeCountList }">
							<option value="${diaryTypeCount.diaryTypeId }" ${diaryTypeCount.diaryTypeId==diary.typeId?'selected':'' }>${diaryTypeCount.typeName }</option>
						</c:forEach>
					</select>
				</div>
				<!-- 操作按钮部分 -->
				<div>
					<!--在修改日志时候的保存日志的id，将其设置为隐藏域-->
					<input type="hidden" name="diaryId" id="diaryId" value="${diary.diaryId}"/>
					<input type="submit" class="btn btn-primary" value="保存"/>
					<button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>
					<font id="error" color="red">${error }</font>
				</div>
			</div>
		</form>
</div>
</body>
</html>